﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Chbl.DAL;
using Chbl.Models;

namespace Chbl.Controllers
{
    public class TeamController : Controller
    {
        private ChblDb _db = new ChblDb();

        public TeamController(ChblDb chblDb)
        {
            _db = chblDb;
        }

        //
        // GET: /Team/
        public ActionResult Index()
        {
            var model = _db.SeasonDivisions;
                    
            return View(model);
        }


        public ActionResult Create()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Create(Team team)
        {
            _db.Teams.Add(team);
            _db.SaveChanges();
            return RedirectToAction("Index");
        }

        public ActionResult TeamPlayers(int teamId)
        {
            var model = _db.TeamPlayers
                .Where(tp => tp.TeamId == teamId)
                .Select(tp => tp.Player);
            return View(model);

        }
    }
}
